//
//  M1_PersonalHeaderView.m
//  NewMarryU
//
//  Created by Cedar on 2018/7/12.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1_PersonalHeaderView.h"

@implementation M1_PersonalHeaderView

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.frame = CGRectMake(0, 0, SCREENWIDTH, 260 + STATUS_HEIGHT);
    
    [self.m1_name mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.m1_coverImage.mas_right).offset(20);
        make.bottom.equalTo(self.m1_age.mas_top).offset(-11);
        make.right.mas_lessThanOrEqualTo(-35);
    }];
    
    CGFloat left = (SCREENWIDTH - 40 * 4) / 5;
    [self.m1_idcardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(19);
        make.left.offset(left);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.m1_educationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(19);
        make.left.equalTo(self.m1_idcardBtn.mas_right).offset(left);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.m1_houseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(19);
        make.left.equalTo(self.m1_educationBtn.mas_right).offset(left);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];

    [self.m1_carsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(19);
        make.left.equalTo(self.m1_houseBtn.mas_right).offset(left);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.m1_idcardLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m1_idcardBtn.mas_centerX);
        make.top.equalTo(self.m1_idcardBtn.mas_bottom).offset(10);
    }];
    
    [self.m1_educationLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m1_educationBtn.mas_centerX);
        make.top.equalTo(self.m1_educationBtn.mas_bottom).offset(10);
    }];
    
    [self.m1_houseLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m1_houseBtn.mas_centerX);
        make.top.equalTo(self.m1_houseBtn.mas_bottom).offset(10);
    }];
    
    [self.m1_carLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m1_carsBtn.mas_centerX);
        make.top.equalTo(self.m1_carsBtn.mas_bottom).offset(10);
    }];
    
    
    [self.m1_idcardDesLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(19);
        make.left.offset(left);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.m1_educationDesLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(19);
        make.left.equalTo(self.m1_idcardBtn.mas_right).offset(left);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.m1_houseDesLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(19);
        make.left.equalTo(self.m1_educationBtn.mas_right).offset(left);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.m1_carDesLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(19);
        make.left.equalTo(self.m1_houseBtn.mas_right).offset(left);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
}

- (void)awakeFromNib{
    [super awakeFromNib];
    
    self.m1_coverImage.layer.cornerRadius = 10.0;
    self.m1_coverImage.layer.masksToBounds = YES;
    
    self.m1_coverShadow.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
    self.m1_coverShadow.layer.cornerRadius = 10.0;
    self.m1_coverShadow.layer.masksToBounds = YES;
    
    self.m1_shadowImage.image = LOAD_LOCAL_IMG(@"bgView");
    
    self.m1_idcardDesLbl.backgroundColor = [UIColor m1_colorHex:0xffffff alpha:0.4];
    self.m1_educationDesLbl.backgroundColor = [UIColor m1_colorHex:0xffffff alpha:0.4];
    self.m1_houseDesLbl.backgroundColor = [UIColor m1_colorHex:0xffffff alpha:0.4];
    self.m1_carDesLbl.backgroundColor = [UIColor m1_colorHex:0xffffff alpha:0.4];
    
    [self m1_setData];
}

- (void)m1_setData{
    [self.m1_coverImage sd_setImageWithURL:[NSURL URLWithString:[M1User user].basic.avatar.img.url] placeholderImage:LOAD_LOCAL_IMG(@"bgView")];
    
    [self.m1_shadowImage sd_setImageWithURL:[NSURL URLWithString:[M1User user].basic.avatar.img.url] placeholderImage:LOAD_LOCAL_IMG(@"bgView")];

    self.m1_name.text = [M1User user].basic.name;
    
    if ([[M1User user].basic.high length] <= 0 || [[M1User user].basic.high integerValue] == 0) {
        self.m1_age.text = [NSString stringWithFormat:@"%@岁·%@", [M1User user].basic.age, [M1User user].basic.constellation];
    }else{
        self.m1_age.text = [NSString stringWithFormat:@"%@岁·%@cm·%@", [M1User user].basic.age, [M1User user].basic.high, [M1User user].basic.constellation];
    }
    
    
//    if ([M1User user].status.integrity == 1) {
//        self.m1_completeness.text = @"资料已完善";
//    }else{
//        self.m1_completeness.text = @"资料未完善";
//    }
    
    [self.m1_likeBtn setTitle:[M1User user].status.liked_count forState:UIControlStateNormal];
    
    if ([M1User user].status.member_fees_status == 0) {
        self.m1_vip.hidden = YES;
    }else{
        self.m1_vip.hidden = NO;
    }
    if ([M1User user].basic.identity_info.identity_auth.auth_status == 1) {
        [self.m1_idcardBtn setImage:LOAD_LOCAL_IMG(@"personal_icon_idcard") forState:UIControlStateNormal];
    }else{
        [self.m1_idcardBtn setImage:LOAD_LOCAL_IMG(@"personal_icon_idcard_no") forState:UIControlStateNormal];
    }
    
    if ([M1User user].basic.education_info.education_auth.auth_status == 1) {
        [self.m1_educationBtn setImage:LOAD_LOCAL_IMG(@"personal_icon_education") forState:UIControlStateNormal];
    }else{
        [self.m1_educationBtn setImage:LOAD_LOCAL_IMG(@"personal_icon_education_no") forState:UIControlStateNormal];
    }

    if ([M1User user].basic.house_info.house_auth.auth_status == 1) {
        [self.m1_houseBtn setImage:LOAD_LOCAL_IMG(@"personal_icon_house") forState:UIControlStateNormal];
    }else{
        [self.m1_houseBtn setImage:LOAD_LOCAL_IMG(@"personal_icon_house_no") forState:UIControlStateNormal];
    }

    if ([M1User user].basic.car_info.car_auth.auth_status == 1) {
        [self.m1_carsBtn setImage:LOAD_LOCAL_IMG(@"personal_icon_cars") forState:UIControlStateNormal];
    }else{
        [self.m1_carsBtn setImage:LOAD_LOCAL_IMG(@"personal_icon_cars_no") forState:UIControlStateNormal];
    }
    
    self.m1_idcardDesLbl.hidden = [M1User user].basic.identity_info.identity_auth.auth_status != 2;
    self.m1_educationDesLbl.hidden = [M1User user].basic.education_info.education_auth.auth_status != 2;
    self.m1_houseDesLbl.hidden = [M1User user].basic.house_info.house_auth.auth_status != 2;
    self.m1_carDesLbl.hidden = [M1User user].basic.car_info.car_auth.auth_status != 2;
}

- (IBAction)m1_certificationAction:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(m1_certificationPushVC:)]) {
        [self.delegate m1_certificationPushVC:sender.tag];
    }
}

- (IBAction)m1_likeAction:(id)sender {
    if ([self.delegate respondsToSelector:@selector(m1_pushToLikeVC)]) {
        [self.delegate m1_pushToLikeVC];
    }
}

- (IBAction)detailsAction:(id)sender {
    if ([self.delegate respondsToSelector:@selector(m1_pushToDetailsVC)]) {
        [self.delegate m1_pushToDetailsVC];
    }
}

- (IBAction)m1_photoAction:(UITapGestureRecognizer *)sender {
    if ([self.delegate respondsToSelector:@selector(m1_pushToPhotoAlbumVC)]) {
        [self.delegate m1_pushToPhotoAlbumVC];
    }
}
@end
